﻿using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.ShowSpeechBubble, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_ShowSpeechBubble : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.ShowSpeechBubble;

        public override string name => LevelEditorConst.ShowSpeechBubble;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.ShowSpeechBubble, "LevelEntityBubbleGroup表ID")] public int groupID;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_ShowSpeechBubble()
            {
                // tag = this.tag,
                groupID = this.groupID
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tag = x);
            return rConfig;
        }
        
        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_ShowSpeechBubble rNode)
            {
                this.groupID = rNode.groupID;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_ShowSpeechBubble rConfig)
            {
                this.SyncTarget(rConfig.tag);
            }
        }
    }
}